#
# @lc app=leetcode.cn id=38 lang=python3
#
# [38] 外观数列
#


# @lc code=start
class Solution:
    def countAndSay(self, n: int) -> str:
        """
        :type n: int
        :rtype: str
        """
        def makeNum(num):
            newNum = ['1', num[0]]
            for j in num[1:]:
                if j == newNum[-1]:
                    newNum[-2] = str(1 + int(newNum[-2]))
                else:
                    newNum.extend(['1', j])
            return ''.join(newNum)

        def count(n, num='1'):
            if n == 1:
                return num
            else:
                return count(n - 1, makeNum(num))

        return count(n)


# @lc code=end
